//js
$(function(){
var _currentIndex = 0;
var _currentHeight = 0;
var _isScrolling = false;
	
function init(){
	$(window).resize(onResize);
	// $(window).scroll(onScroll);
	$(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', onScroll);
	$(window).resize();
	step0();
}

function onResize() {
	var w = $(window).width();
	var h = $(window).height();
	_currentHeight = h;
	$('#w-images').css({height:h});
	// _photoHeighs = [0];
	$('#w-images img').each(function(){
		var index = $(this).index();
		// $(this).css({height:h, top: h * index});
		// console.log($(this).position().top);
		// _photoHeighs.push($(this).position().top + $(this).height());
	});
}

function onScroll(event) {
	event.preventDefault();
	// var pos = $(window).scrollTop();
  var delta = event.originalEvent.wheelDelta || -event.originalEvent.detail;
  console.log('delta', delta);
  if(!_isScrolling){
  	_isScrolling = true;
		//top
		if(delta < 0){
			if(_currentIndex + 1 < $('#w-images p img').length){
				_currentIndex++;
			}
		//bottom
		}else if(delta > 0){
			if(_currentIndex - 1 >= 0){
				_currentIndex--;
			}
		}
		switch(_currentIndex){
			case 0:
				step0();
				break;
			case 1:
				step1();
				break;
			case 2:
				step2();
				break;
		}
		TweenLite.to($('#w-images p'), 1, {top:-_currentIndex * _currentHeight, onComplete:onScrollComplete, ease:Power4.easeOut});
	}
}

function onScrollComplete(){
	_isScrolling = false;
}

/*
function transform() {
	console.log('_currentIndex', _currentIndex);
	var y = $('#w-images img').eq(_currentIndex).position().top;
	console.log('y', y);
	TweenLite.to(window, 2, {scrollTo:{y:y}, ease:Power2.easeOut});
}
*/
/*
function resizeOne($img){
  var key = $img.attr('key');
  var d = _dimensions[key];
  var pW, pH;
  //flag: algin pattern, 0 horizontal; 1 vertical
  var x = 0, y = 0, newW = 0, newH = 0, ratio = 0;
  if(d){
    pW = _width / d.width;
    pH = _height / d.height;
    //if the ratio of width is greater than height's, then using width's
    if (pW > pH){ 
      ratio = pW;
    }else{
      ratio = pH;
    }
    newW = d.width * ratio;
    newH = d.height * ratio;
    x = (_width - newW) / 2;
    y = (_height - newH) / 2;
    // console.log(x, y);
    $img.css({width:newW, height:newH, left:x, top:y});
  }
}
*/

function step0() {
	//
	$('#w-dots li').removeClass('wd-selected');
	$('#wb-btns').removeClass('wb-btns-up');
	//
	$('#w-banner').addClass('w-banner-show');
	$('#w-dots li:eq(0)').addClass('wd-selected');
}

function step1() {
	//
	$('#w-dots li').removeClass('wd-selected');
	$('#w-banner').removeClass('w-banner-up');
	$('#wh-want').removeClass('wh-want-zoomin');
	$('#wh-slogan').removeClass('wh-slogan-show');
	$('#wb-btns').removeClass('wb-btns-down');
	//
	$('#wb-btns').addClass('wb-btns-up');
	$('#w-dots li:eq(1)').addClass('wd-selected');
}

function step2() {
	$('#w-dots li').removeClass('wd-selected');
	//
	$('#w-dots li:eq(2)').addClass('wd-selected');
	$('#w-banner').addClass('w-banner-up');
	$('#wh-want').addClass('wh-want-zoomin');
	$('#wh-slogan').addClass('wh-slogan-show');
	$('#wb-btns').addClass('wb-btns-down');
}

function step3() {
	// body...
}


init();
});